<template>
  <div>
    <div v-for="(item, index) in payList" :key="index" class="pay-block">
      <div
        :class="[
          'radio-group',
          {
            highlight:
              item.smpPayTypeBO.isChangeFlag && item.smpPayTypeBO.highlightFlag
          }
        ]"
      >
        <el-radio
          v-model="item.smpPayTypeBO.radio"
          :label="item.smpPayTypeBO.payTypeName"
        />
      </div>
      <div class="ccui-multifunctional-table-wrapper">
        <el-table
          :data="item.smpPayTypeItemBOS"
          :fit="true"
          border
          class="ccui-multifunctional-table"
          :row-class-name="tableRowClassName"
        >
          <el-table-column label="支付次数" type="index" width="80" />

          <el-table-column label="规定时间" width="180">
            <template slot-scope="{ row }">
              <span>{{ row.fixTime }}</span>
              <span>{{ row.fixTimeLength }}</span>
              <span>{{ jsList.fixTimeMap[row.fixTimeCode] }}</span>
              <span v-if="row.fixTimeCode === 0">{{
                jsList.fixTimeEnum1.find(_ => _.dicKey === row.fixTimeSonCode)
                  .dicValue
              }}</span>
              <span v-if="row.fixTimeCode === 3">{{
                row.exchangeRateRefDate
              }}</span>
            </template>
          </el-table-column>

          <el-table-column label="付款方式">
            <template slot-scope="{ row }">
              <el-radio v-model="row.payTypeName" :label="row.payTypeName" />
            </template>
          </el-table-column>

          <el-table-column label="付款比率">
            <template slot-scope="{ row }">
              <span class="table-span">付 {{ row.payRate }} %</span>
              <el-radio
                v-if="row.isRetentionMoney"
                v-model="row.isRetentionMoney"
                :label="row.isRetentionMoney"
              />
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import jsList from "../js";
export default {
  name: "detailPaymentMode",
  props: {
    detail: {
      type: Object,
      default: () => []
    }
  },
  data() {
    return {
      jsList,
      radio: "",
      payList: []
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.payList = this.detail.payTypeListBOS.map(n => ({
        smpPayTypeBO: {
          ...n.smpPayTypeBO,
          radio: n.smpPayTypeBO?.payTypeName,
          payType: n.smpPayTypeBO?.payType
        },
        smpPayTypeItemBOS: n.smpPayTypeItemBOS.map(m => ({
          ...m,
          payTypeName: jsList.payTypeEnum.find(_ => _.dicKey === m.payTypeCode)
            .dicValue,
          isRetentionMoney:
            m.isRetentionMoney !== null && [0, 1].includes(m.isRetentionMoney)
              ? jsList.paymentRatio.find(_ => _.dicKey === m.isRetentionMoney)
                  .dicValue
              : ""
        }))
      }));
    },
    // 高亮行
    tableRowClassName({ row }) {
      if (row.isChangeFlag && row.highlightFlag) {
        return "success-row";
      } else {
        return "";
      }
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/ .ccui-multifunctional-table-wrapper {
  .el-table td,
  .el-table th.is-leaf {
    border-right: 1px solid #edf2fc;
  }
  .table-span {
    margin-right: 20px;
  }
  .success-row {
    .el-radio__input.is-checked + .el-radio__label {
      color: #ff6913;
    }
  }
}
.pay-block:nth-last-child(1) {
  margin-bottom: 50px;
}
.pay-block + .pay-block {
  margin-top: 20px;
}
.radio-group {
  margin-bottom: 20px;
  &.highlight {
    /deep/ .el-radio__input.is-checked + .el-radio__label {
      color: #ff6913;
    }
  }
}
</style>
